﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyBlog.Entity;
using MyBlog.Common;
using System.Data;
using System.Data.SqlClient;
using log4net;

namespace MyBlog.DAL
{
    public class DAL_ASMX_UserLogon
    {
        private static log4net.ILog myLogger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public bool UserLogon(string usr, string pwd)
        {
            try
            {
                int i = 0;
                i = int.Parse(DBHelper.GetSingle("select count(*) from T_Users where username=@user and [password]=@pass",
                    new SqlParameter[]{
                        new SqlParameter("@user",usr),
                        new SqlParameter("@pass",pwd)
                    }).ToString());

                if (i == 1)
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                myLogger.Error(ex.Message, ex);
                throw;
            }
        }

        public string GetUserUUID(string usr)
        {
            try
            {
                return DBHelper.GetSingle("select uuid from T_User where username=@user",
                    new SqlParameter[]{
                        new SqlParameter("@user",usr)
                    }).ToString();
            }
            catch (Exception ex)
            {
                myLogger.Error(ex.Message, ex);
                throw;
            }
        }
    }
}
